home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / file / managers / git-4.3 / git-4 / git-4.3.7 / src / gitmatch.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-08  |  1.5 KB  |  67 lines

  1. /* gitmatch.c -- an utility used internally by git to match file names against
  2.    different shell-like patterns. */
  3.  
  4. /* Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
  5.  
  6.    This program is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 2, or (at your option)
  9.    any later version.
  10.  
  11.    This program is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with this program; if not, write to the Free Software
  18.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* Written by Tudor Hulubei and Andrei Pitis.  */
  21.  
  22.  
  23. #ifdef HAVE_CONFIG_H
  24. #include <config.h>
  25. #endif
  26.  
  27. #include <stdio.h>
  28.  
  29. #include "fnmatch.h"
  30.  
  31.  
  32. char *program;
  33.  
  34.  
  35. int
  36. usage()
  37. {
  38.     fprintf(stderr, "%s: GIT internal program.\n", program);
  39.     exit(255);
  40. }
  41.  
  42.  
  43. /*
  44.  * argv[1] = string
  45.  * argv[2], argv[3], ... = patterns
  46.  * return value = no of pattern that matches
  47.  */
  48.  
  49. int
  50. main(argc, argv)
  51.     int argc;
  52.     char *argv[];
  53. {
  54.     int i, flags = FNM_PERIOD | FNM_PATHNAME;
  55.  
  56.     program = argv[0];
  57.  
  58.     if (argc < 3)
  59.         usage();
  60.  
  61.     for (i = 0; i < argc - 2; i++)
  62.         if (fnmatch(argv[i + 2], argv[1], flags) != FNM_NOMATCH)
  63.             return i + 1;
  64.  
  65.     return 0;
  66. }
  67.